package learn_250214;

public class quickSort {
    public static void main(String[] args) {
        int[] a = {4,2,1,5,3};
        quick_Sort(a,0,a.length-1);
        for (int i : a) {
            System.out.print(i + " ");
        }
    }
    private static void quick_Sort(int[] arr,int low,int high){
        if(low>high){
            return;
        }
        int tmp = arr[low];
        int i = low;
        int j = high;
        while(i<j){
            while(arr[j]>=tmp && j>i){
                j--;
            }
            while(arr[i]<=tmp && j>i){
                i++;
            }
            if(i<j){
                int tmp_pos = arr[j];
                arr[j] =arr[i];
                arr[i] = tmp_pos;
            }

        }
        arr[low] = arr[j];
        arr[j] = tmp;
        quick_Sort(arr,low,j-1);
        quick_Sort(arr,j+1,high);
    }


}
